@extends('Admin.layout.layout')

@section('content')
<div class="col-lg-12">
    <div class="panel panel-default">
        <div class="panel-heading">
        用户列表
        </div> 

<div class="panel-body">
    <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
    	<div class="row">
    	<form action="{{url('/admin/user/index')}}" method="get">
    		<div class="col-sm-6">
    			<div id="dataTables-example_filter" class="dataTables_filter">
    				<label>用户名:<input class="form-control input-sm" placeholder="" aria-controls="dataTables-example" name="word" type="search"> <button type="submit" class="btn btn-primary">搜索</button></label>
    			</div>
    		</div>
    	</form>
    	</div>
    	<div class="row">
        <!-- /.panel-heading -->
        <div class="panel-body">
            <div class="table-responsive">
                <table class="table">
                    <thead>
                        <tr>
                            <th>id</th>
                            <th>用户名</th>
                            <th>邮箱</th>
                            <th>手机号</th>
                            <th>性别</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    @foreach($user as $k=>$v)
                        <tr class="success">
                            <td class="sid">{{$v->id}}</td>
                            <td>{{$v->name}}</td>
                            <td>{{$v->email}}</td>
                            <td>{{$v->phone}}</td>
                            <td>{{str_replace([1,2,3],['男','女','保密'],$v->sex)}}</td>
                            <td><p class="fa fa-trash-o"></p><a class="delete" href
                            ="">删除</a> | <p class="fa fa-wrench"></p><a href="{{url('/admin/user/edit',['id' => $v -> id])}}">修改</a></td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
            <!-- /.table-responsive -->
        </div>
        <!-- /.panel-body -->
    </div>
    <!-- /.panel -->

	<div class="col-lg-offset-9">{!! $user->appends($request)->render() !!}</div> 

</div>  

@endsection
@section('myjs')
<script type="text/javascript">
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});
	$('.delete').click(function(){
		var id = $(this).parents('tr').find('.sid').html();
		// 发送ajax
		var tr = $(this);
		$.post('/admin/user/delete',{id:id},function(data){
			if(data == 1){
				tr.parents('tr').remove();
			}else{
				alert('删除失败');
			}
		})
		return false;
	})
</script>
@endsection
